from Base.WriteExcel import Write_excel
import os, time
from Base import  GetYamlFile



"""
写入报告（Excel形式）
"""
def WriteResult(result):
    YmlList = GetYamlFile.getYamlFile()
    CaseResultPath = YmlList["CaseResultPath"]
    today = time.strftime("%Y_%m_%d")
    CaseResultPath = CaseResultPath + "\Result" + today + ".xlsx"
    # 获取项目路径
    PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
    # join 拼接具体路径
    REPORT_XLSX_DIR = os.path.join(PROJECT_ROOT, CaseResultPath)
    rowNum = result["rowNum"]
    wt = Write_excel(REPORT_XLSX_DIR, "Result")
    wt.write(1, 1, "用例名称")
    wt.write(1, 2, "请求方式")
    wt.write(1, 3, "URL")
    wt.write(1, 4, "params")
    wt.write(1, 5, "hopeResult")
    wt.write(1, 6, "actualResult")
    wt.write(1, 7, "是否通过")
    wt.write(1, 8, "运行时间(ms)")
    wt.write(rowNum, 1, result["testName"])
    wt.write(rowNum, 2, result["method"])
    wt.write(rowNum, 3, result["url"])
    wt.write(rowNum, 4, result["params"])
    wt.write(rowNum, 5, result["hopeResult"])
    wt.write(rowNum, 6, result["actualResult"])
    wt.write(rowNum, 7, result["result"])
    wt.write(rowNum, 8, result["time"])
